package com.mega.fe.util.klass;

import com.mega.fe.util.MEGA;
import net.minecraft.client.Minecraft;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.system.Checks;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
import org.lwjgl.system.NativeType;

import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodType;
import java.nio.ByteBuffer;
import java.time.LocalTime;

public class EventUtil {
    public static void glfwSetWindowTitle() {
        MemoryStack stack = MemoryStack.stackGet();
        int stackPointer = stack.getPointer();

        try {
            stack.nUTF8("FantasyEnding 1.20.1-"+ LocalTime.now(), true);
            long titleEncoded = stack.getPointerAddress();
            try {
                MethodHandle nglfwSetWindowTitle = MEGA.IMPL_LOOKUP().findStatic(GLFW.class, "nglfwSetWindowTitle", MethodType.methodType(void.class, long.class, long.class));

                nglfwSetWindowTitle.invoke(Minecraft.getInstance().window.getWindow(), titleEncoded);
            } catch (Throwable t) {
                t.printStackTrace();
            }
        } finally {
            stack.setPointer(stackPointer);
        }


    }
}
